const cloud = require('wx-server-sdk');
cloud.init({
  env:"xiaotiao-6gcr9hxy3d8aa90f"
});
const db = cloud.database();
exports.main = async (event, context) => {
  var openid = event.openid;
  var records = [];
  try{
    await db.collection('ClockInRecords').where({
      _openid: openid
    }).get().then(res=>{
      if(res.data.length==0){
        return{
          event:event,
          success:false,
          records:null
        };
      }else{
      records = res.data[0]._records
      }
    }).catch(res=>{
      records = null
    })
    return{
      event:event,
      success:true,
      records:records
    };
  }catch(e){
    return{
      event:event,
      success:false,
      records:records
    }
  }
}